package com.bullsora.kindlerss.business;

import com.bullsora.kindlerss.model.Subscription;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.stereotype.Component;
import org.springframework.ui.velocity.VelocityEngineUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * @author sorin.buliarca@iquesint.com
 */
@Component
public class StructuredHtmlGenerator {

  private static final String SUBSCRIPTION_TEMPLATE = "subscriptionTemplate.vm";

  private VelocityEngine velocityEngine;

  public String generateHtmlForSubscription(Subscription subscription) {
    DateFormat dateFormat = new SimpleDateFormat("MMM dd");
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("subscription", subscription);
    model.put("dateFormat", dateFormat);
    return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, SUBSCRIPTION_TEMPLATE, model);
  }

  public VelocityEngine getVelocityEngine() {
    return velocityEngine;
  }

  public void setVelocityEngine(VelocityEngine velocityEngine) {
    this.velocityEngine = velocityEngine;
  }
}
